<template>
  <div class="app-container">
    <Search-content :queryParams="queryParams" labelWidth="120px" @query="handleQuery" @reset="resetQuery">
      <el-col :span="6">
        <el-form-item label="车牌号:">
          <el-input v-model="queryParams.carNo" clearable placeholder="请输入车牌号"/>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="车架号:">
          <el-input v-model="queryParams.vinNo" clearable placeholder="请输入车架号"/>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="品牌/车系/车型:">
          <linkage-select @changeNode="linkageChange" v-model="linkageList" placeholder="请选择品牌/车系/车型"/>
        </el-form-item>
      </el-col>
      <!-- <el-col :span="6">
        <el-form-item label="牌照性质:">
          <el-input v-model="queryParams.licenseNature" clearable placeholder="请输入牌照性质"/>
        </el-form-item>
      </el-col> -->

      <el-col :span="6">
        <el-form-item label="排放标准:">
          <el-input v-model="queryParams.environmentalStandards" clearable placeholder="请输入排放标准"/>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="车况等级:">
          <el-select v-model="queryParams.vehicleConditionLevel" placeholder="请选择车况等级" clearable>
            <el-option v-for="dict in dict.type.vehicle_condition_level_type" :key="dict.value" :label="dict.label"
                       :value="dict.value"/>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="车辆产权:">
          <el-input v-model="queryParams.propertyRightName" clearable placeholder="请输入车辆产权"/>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="申请人:">
          <el-input v-model="queryParams.proposer" clearable placeholder="请输入申请名称"/>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="申请时间:">
          <el-date-picker v-model="valueDate" type="daterange" placeholder="请选择日期" range-separator="-"
                            @change="handleTime"  value-format="yyyy-MM-dd"
                          start-placeholder="开始日期" end-placeholder="结束日期" style="width: 100%;"/>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="处置状态:">
          <el-select v-model="queryParams.disposalStatus" placeholder="请选择处置状态" clearable>
            <el-option v-for="dict in dict.type.disposal_status_type" :key="dict.value" :label="dict.label"
                       :value="dict.value"/>
          </el-select>
        </el-form-item>
      </el-col>
    </Search-content>

    <div class="card-wrap card-padding">
      <div class="table-title-wrap justify-end">
        <el-button size="mini" @click="handleNew"
                   v-hasPermi="['routineApplyFor:routineApplyForList:new']" type="primary">
          新增申请
        </el-button>
      </div>

      <table-page :loading="loading" :dataList="dataList" :total="total" :page.sync="queryParams.pageNum"
                  :limit.sync="queryParams.pageSize" @setSizeCurrent="handleList" border>

        <template slot="tableColAc">
          <el-table-column label="操作" align="center" fixed="left" width="150">
            <template #default="{row}">
              <el-button size="mini" type="text" @click="handleView(row, 'view')"
                         v-hasPermi="['routineApplyFor:routineApplyForList:view']">
                查看
              </el-button>

              <el-button size="mini" type="text" @click="handleCancel(row)"
                         v-if="[2].includes(Number(row.disposalStatus))"
                         v-hasPermi="['routineApplyFor:routineApplyForList:cancel']">
                撤销
              </el-button>

              <el-button size="mini" type="text" @click="handleAdd(row)"
                         v-if="[12].includes(Number(row.disposalStatus))"
                         v-hasPermi="['routineApplyFor:routineApplyForList:cancel']">
                处置车辆
              </el-button>

              <el-button size="mini" type="text" @click="handleTransferOwnership(row)"
                         v-if="[9].includes(Number(row.disposalStatus))"
                         v-hasPermi="['routineApplyFor:routineApplyForList:transferOwnership']">
                车辆过户
              </el-button>

            </template>
          </el-table-column>

        </template>

        <template slot="tableCol">
          <el-table-column align="center" label="常规处置编号" min-width="215" show-overflow-tooltip
                           prop="vehicleDisposalNo"/>

          <el-table-column align="center" label="车牌号" min-width="140" show-overflow-tooltip prop="carNo"/>

          <el-table-column align="center" label="车架号" min-width="180" show-overflow-tooltip prop="vinNo"/>

          <el-table-column  label="品牌/车型/车款" show-overflow-tooltip min-width="400">
            <template #default="{row}">
              {{ row.brandName }}{{ row.seriesName }}{{ row.modelName }}
            </template>
          </el-table-column>

          <el-table-column align="center" label="排放标准" show-overflow-tooltip min-width="130"
                           prop="environmentalStandards"/>

          <el-table-column align="center" label="登记日期" show-overflow-tooltip min-width="140"
                           prop="registerTime">
            <template #default="{row}">
              {{ row.registerTime || '-' }}
            </template>
          </el-table-column>

          <el-table-column align="center" label="预警车龄" show-overflow-tooltip min-width="120"
                           prop="carAge"/>

          <el-table-column align="center" label="车况等级" show-overflow-tooltip min-width="100"
                           prop="vehicleConditionLevel">
            <template #default="{row}">
              {{ selectDictLabel(dict.type.vehicle_condition_level_type, row.vehicleConditionLevel) }}
            </template>
          </el-table-column>

          <el-table-column align="center" label="车辆产权" show-overflow-tooltip min-width="130"
                           prop="propertyRightName"/>

          <el-table-column align="center" label="处置状态" show-overflow-tooltip min-width="120">
            <template #default="{row}">
              {{ selectDictLabel(dict.type.disposal_status_type, row.disposalStatus) }}
            </template>
          </el-table-column>

          <el-table-column align="center" label="申请人" show-overflow-tooltip min-width="120"
                           prop="proposer"/>

          <el-table-column align="center" label="申请时间" show-overflow-tooltip min-width="140">
            <template #default="{row}">
              {{ row.proposerTime || '-' }}
            </template>
          </el-table-column>

        </template>
      </table-page>
    </div>

    <transfer-ownership ref="refTransferOwnership" @refresh="refresh"/>
  </div>
</template>

<script>
import LinkageSelect from "@/views/components/linkageSelect.vue";
import SearchContent from "@/components/SearchContent/index.vue";
import transferOwnership from '../../components/routineDisposal/routineApplyFor/transferOwnership.vue'
import * as apis from '@/api/vehicleDisposal/routineApplyFor.js'

export default {
  name: "RoutineApplyForList",
  dicts: ['warning_state_type', 'vehicle_condition_level_type', 'disposal_status_type'],
  components: {SearchContent, LinkageSelect, transferOwnership},
  //常规处置申请
  computed: {},
  watch: {},
  data() {
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        carNo: "",
        vinNo: "",
        brandId: "",
        seriesId: "",
        modelId: "",
        licenseNature: "",
        environmentalStandards: "",
        vehicleConditionLevel: "",
        propertyRightName: "",
        proposer: "",
        applicationStartTime:"",
        applicationEndTime:""
      },
      linkageList: [],
      dataList: [],
      total: 0,
      loading: false,
      valueDate: [],
    };
  },
  created() {
    this.handleList()
  },
  mounted() {
  },
  methods: {
    handleTime(val){
      if (val) {
        this.queryParams.applicationStartTime = val[0]
        this.queryParams.applicationEndTime = val[1]
      }
    },

    handleQuery() {
      this.queryParams.pageNum = 1;
      this.handleList();
    },

    resetQuery() {
      this.linkageList = []
      this.valueDate = []
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        carNo: "",
        vinNo: "",
        brandId: "",
        seriesId: "",
        modelId: "",
        licenseNature: "",
        environmentalStandards: "",
        vehicleConditionLevel: "",
        propertyRightName: "",
        proposer: "",
        applicationStartTime:"",
        applicationEndTime:""
      };
      this.handleList();
    },

    linkageChange(val) {
      this.linkageList = val;
      if (val) {
        this.queryParams.brandId = val[0] ? val[0].id : "";
        this.queryParams.seriesId = val[1] ? val[1].id : "";
        this.queryParams.modelId = val[2] ? val[2].id : "";
      } else {
        this.queryParams.brandId = "";
        this.queryParams.seriesId = "";
        this.queryParams.modelId = "";
      }
      this.$forceUpdate();
    },

    //列表
    async handleList() {
      this.loading = true;
      try {
        const res = await apis.vehicleDisposalList(this.queryParams);
        this.dataList = res.rows;
        this.total = res.total;
      } catch (e) {
        console.error("获取失败", e);
      } finally {
        this.loading = false;
      }
    },

    //新增
    handleNew() {
      this._toPage({
        path: "/VehicleDisposal/RoutineDisposal/RoutineApplyForNew",
        name: 'RoutineApplyForNew',
        query: {
          type: "edit",
          path: 'RoutineApplyForList'
        }
      })
    },

    handleAdd(row){
      this._toPage({
        path: "/VehicleDisposal/RoutineDisposal/RoutineApplyForNew",
        name: 'RoutineApplyForNew',
        query: {
          id:row.vehicleDisposalId,
          type: "edit",
          path: 'RoutineApplyForList',
          flowId:row.flowId
        }
      })
    },

    //查看
    handleView(row) {
      let route, name, path
      if ([2, 9].includes(Number(row.disposalStatus))) {
        route = "/VehicleDisposal/RoutineDisposal/RoutineHandleDetails"
        name = "RoutineHandleDetails"
        path = "RoutineApplyForList"
      } else {
        route = "/VehicleDisposal/RoutineDisposal/RoutineApplyForDetails"
        name = "RoutineApplyForDetails"
        path = "RoutineApplyForList"
      }
      this._toPage({
        path: route,
        name: name,
        query: {
          type: "view",
          path: path,
          id: row.vehicleDisposalId,
          flowId:row.flowId
        }
      })
    },

    //撤销
    handleCancel(row) {
      this._toPage({
        path: "/VehicleDisposal/RoutineDisposal/RoutineApplyForCancel",
        name: 'RoutineApplyForCancel',
        query: {
          type: "edit",
          id: row.vehicleDisposalId,
          revocationId:row.revocationId,
          path: 'RoutineApplyForList',
          flowId:row.flowId
        }
      })
    },

    //车辆过户
    handleTransferOwnership(row) {
      this.$refs.refTransferOwnership.handleOpen(row.vehicleDisposalId)
    },

    refresh() {
      this.queryParams.pageNum = 1;
      this.handleList();
    }
  },
};
</script>

<style scoped lang=""></style>


